<%@ page language="java"  pageEncoding="UTF-8"%>
<%@page import="java.util.List"%>
<%@page import="com.fick.hibernate.dao.SysMenuDAO"%>
<%@page import="com.fick.hibernate.model.SysMenu"%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>系统菜单</title>
<style type="text/css">
body {
	margin-left: 0px;
	margin-top: 0px;
	margin-right: 0px;
	margin-bottom: 0px;
}
.STYLE1 {font-size: 12px;}
.STYLE4 {
	font-size: 12px;
	color: #1F4A65;
	font-weight: bold;
}

a:link {
	font-size: 12px;
	color: #06482a;
	text-decoration: none;

}
a:visited {
	font-size: 12px;
	color: #06482a;
	text-decoration: none;
}
a:hover {
	font-size: 12px;
	color: #FF0000;
	text-decoration: underline;
}
a:active {
	font-size: 12px;
	color: #FF0000;
	text-decoration: none;
}
.STYLE7 {font-size: 12px;}

</style>
<script type="text/javascript" src="js/meihuaxue.js"></script>
<script type="text/javascript" src="js/prototype.js"></script>
<script type="text/javascript" src="js/check.js"></script>
<script type="text/javascript">
function sys(){
	//点击系统菜单时出现添加一级菜单
	$("one").style.display="";
	$("detail").style.display="none";
	meunForm.method.value="add";
}
function addOne(){
	$("one").style.display="none";
	$("detail").style.display="";
	$("downButton").style.display="none";
	$("delButton").style.display="none";
	$("parid").value="";
	meunForm.method.value="add";
	meunForm.id.value="";
	meunForm.parid.value="";
	meunForm.menuName.value="";
	meunForm.menuUrl.value="";
	meunForm.menuOrder.value="";
	$("show1").checked=true;
	meunForm.menuAbout.value="";
}
function addSon(){
	$("one").style.display="none";
	$("detail").style.display="";
	$("downButton").style.display="none";
	$("delButton").style.display="none";
	$("parid").value="";
	meunForm.method.value="add";
	meunForm.parid.value=meunForm.id.value;
	meunForm.id.value="";
	meunForm.menuName.value="";
	meunForm.menuUrl.value="";
	meunForm.menuOrder.value="";
	$("show1").checked=true;
	meunForm.menuAbout.value="";
}
function checkForm(){
		if(trim(meunForm.menuName.value)==""){
			alert("菜单名称不能为空！");
			meunForm.menuName.focus();
			return false;
		}
		if(meunForm.menuOrder.value!="" && meunForm.menuOrder.value!="0" && !isInt(meunForm.menuOrder.value,"false")){
			alert("顺序填写不正确！");
			meunForm.menuOrder.focus();
			return false;
		}
		return true;		
}
function show(id,parid,name,url,order,show,about){
	$("one").style.display="none";
	$("detail").style.display="";
	$("downButton").style.display="";
	$("delButton").style.display="";
	meunForm.id.value=id;
	meunForm.parid.value=parid;
	meunForm.menuName.value=name;
	meunForm.menuUrl.value=url;
	meunForm.menuOrder.value=order;
	if(show==0)
		$("show0").checked=true;
	else
		$("show1").checked=true;
	meunForm.menuAbout.value=about;
	meunForm.method.value="update";
}
function del(){
	if(!confirm('您确认删除此菜单和他所有的子菜单吗！\n请注意删除后无法恢复')){
		return false;
	}
	meunForm.method.value="del";
	return true;
	// window.location = "sysMenu.do?method=del&id="+meunForm.id.value;
}
</script>
</head>
<body>
<table width="100%" border="0" align="center" cellpadding="0" cellspacing="0">
  <tr>
    <td height="30">
    <table width="100%" border="0" cellspacing="0" cellpadding="0">
      <tr>
        <td width="15" height="30"><img src="images/tab_03.gif" width="15" height="30" /></td>
        <td width="1101" background="images/tab_05.gif"><img src="images/311.gif" width="16" height="16" />
			<span class="STYLE4">系统菜单管理页面</span></td>
        <td width="281" background="images/tab_05.gif">
        &nbsp;
        </td>
        <td width="14"><img src="images/tab_07.gif" width="14" height="30" /></td>
      </tr>
    </table>
    </td>
  </tr>
  <tr>
    <td>
    <table width="100%" border="0" cellspacing="0" cellpadding="0">
      <tr>
        <td width="9" background="images/tab_12.gif">&nbsp;</td>
        <td bgcolor="#f3ffe3">
        <table width="98%" border="0" cellpadding="0" cellspacing="1" bgcolor="#D7DFE1">
        <tr>
          <td width="30%" height="25" align="center" valign="middle"  bgcolor="#FFFFFF"  class="STYLE1">菜单结构</td>
          <td width="70%" height="25" align="center" valign="middle"  bgcolor="#FFFFFF"  class="STYLE1">菜单项编辑</td>
        </tr>
		
		<tr>
          <td height="25"  valign="middle" bgcolor="#FFFFFF"  class="STYLE1">
		
		<script type="text/javascript">
		 var tree = new MzTreeView("tree");
		  tree.setIconPath("TreeView/");
		  tree.nodes["0_1"] = "text:系统菜单;method:sys()";
		  <%
			//菜单树结构
			List list=new SysMenuDAO().findAll();
		  	if(list!=null && list.size()>0){
				SysMenu sysMenu;
				for(int i=0;i<list.size();i++){
					String par="1";
					String cur="";
		  			sysMenu=(SysMenu)list.get(i);
		  			if(sysMenu.getParId()!=null){
		  				par="0"+sysMenu.getParId().getId();
		  			}
		  			cur="0"+sysMenu.getId();
		  		%>
		  		tree.nodes["<%=par%>_<%=cur%>"] = "text:<%=sysMenu.getMenuName().replaceAll("'","‘").replaceAll("\"","”")%>;method:show('<%=sysMenu.getId()%>','<%=sysMenu.getParId()==null?"":sysMenu.getParId().getId()%>','<%=sysMenu.getMenuName().replaceAll("'","‘").replaceAll("\"","”")%>','<%=sysMenu.getMenuUrl()%>','<%=sysMenu.getMenuOrder()%>','<%=sysMenu.getMenuShow()%>','<%=sysMenu.getMenuAbout().replaceAll("'","‘").replaceAll("\"","”")%>')";
				  <%
				}
		  	}
		  %>
		//写入树


		    document.write(tree.toString());
		    //tree.expandAll();
	</script>
		</td>
          <td height="25" align="left" valign="top" bgcolor="#FFFFFF" style="padding-left:7px"   class="STYLE1">
		  <div id="one">
		 	<input type="button" value="添加一级菜单" onclick="addOne()"> 
		  </div>
		  <div id="detail" style="display:none">
		  <form action="sysMenu.do" method="post" onsubmit="return checkForm();" name="meunForm">
     		 <table width="98%" border="0" cellpadding="0" cellspacing="1" bgcolor="#D7DFE1">
     		 <tr>
          		<td height="25" align="left" valign="middle" bgcolor="#FFFFFF" style="padding-left:7px"  class="STYLE1">
          		 <input type="hidden" id="methodid" name="method" value="add">
		  <input type="hidden" name="id" value="">
		  <input type="hidden" name="parid" value="" id="parid">
          		菜单名称:
          		</td>
          		<td height="25" align="left" valign="middle" bgcolor="#FFFFFF" style="padding-left:7px">
          		<input type="text" id="menuName" name="menuName" MAXLENGTH="50">
          		</td>
          		<td height="25" align="left" valign="middle" bgcolor="#FFFFFF" style="padding-left:7px"  class="STYLE1">
          		菜单地址:
          		</td>
          		<td height="25" align="left" valign="middle" bgcolor="#FFFFFF" style="padding-left:7px">
          		<input type="text" name="menuUrl" MAXLENGTH="500">
          		</td>
          		</tr>
          		<tr>
          		<td height="25" align="left" valign="middle" bgcolor="#FFFFFF" style="padding-left:7px"  class="STYLE1">
          		菜单顺序:
          		</td>
          		<td height="25" align="left" valign="middle" bgcolor="#FFFFFF" style="padding-left:7px">
          		<input type="text" name="menuOrder" >
          		</td>
          		<td height="25" align="left" valign="middle" bgcolor="#FFFFFF" style="padding-left:7px"  class="STYLE1">
          		是否显示:
          		</td>
          		<td height="25" align="left" valign="middle" bgcolor="#FFFFFF" style="padding-left:7px"  class="STYLE1">
          		<input type="radio" name="menuShow" value="1" checked id="show1">是
          		<input type="radio" name="menuShow" value="0" id="show0">否
          		</td>
          		</tr>
          		<tr>
          		<td height="25" align="left" valign="middle" bgcolor="#FFFFFF" style="padding-left:7px"   class="STYLE1">
          		菜单说明:
          		</td>
          		<td height="25" align="left" valign="middle" bgcolor="#FFFFFF" style="padding-left:7px" colspan="3">
          		<textarea name="menuAbout" MAXLENGTH="1000"></textarea>
          		</td>
          		</tr>
          		<tr>
          		<td height="25" align="left" valign="middle" bgcolor="#FFFFFF" style="padding-left:7px" colspan="4"  class="STYLE1">
          			<input type="submit" value="保存" >
          			<input type="submit" value="删除" id="delButton" onclick="return del()">
          			<input type="button" value="添加下级菜单" id="downButton" onclick="addSon()">
          		</td>
          		</tr>
     		 </table>
     		 </form>
     		</div>
		  </td>
        </tr>
       
	   
      </table>
        </td>
        <td width="9" background="images/tab_16.gif">&nbsp;</td>
      </tr>
    </table>
    </td>
  </tr>
  <tr>
    <td height="29">
    <table width="100%" border="0" cellspacing="0" cellpadding="0">
      <tr>
        <td width="15" height="29"><img src="images/tab_20.gif" width="15" height="29" /></td>
        <td background="images/tab_21.gif">
        &nbsp;</td>
        <td width="14"><img src="images/tab_22.gif" width="14" height="29" /></td>
      </tr>
    </table></td>
  </tr>
</table>
</body>
</html>